package com.mi.rof.engineer.guard;

import com.mi.rof.engineer.entity.RepairOrderEvents;
import com.mi.rof.engineer.entity.RepairOrderStates;
import com.mi.rof.entity.SystemException;
import com.mi.rof.entity.enums.ExceptionEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.guard.Guard;
/**
 * @author zwq
 * 判断工程师是否成功进行用户确认
 */
@Slf4j
public class OrderAcceptGuard implements Guard<RepairOrderStates, RepairOrderEvents> {
    @Override
    public boolean evaluate(StateContext<RepairOrderStates, RepairOrderEvents> stateContext) {
        try {
            return (boolean) stateContext.getMessage().getHeaders().get("isOrderConfirmed");
        } catch (Exception e) {
            throw new SystemException(ExceptionEnum.PARAM_LOST.getCode(), ExceptionEnum.PARAM_LOST.getMsg());
        }
    }
}
